﻿using Autofac;
using Autofac.Extras.DynamicProxy;
using GitSyncApp.IServices;
using GitSyncApp.Services;
using GitSyncApp.Services.Jobs;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using System;
using System.IO;
using System.Reflection;

namespace GitSyncApp
{
    public static class ConfigureAppServices
    {
        public static App AddAppServices(this App app, ContainerBuilder builder)
        {
            // job注入需要加入
            builder.RegisterType<StdSchedulerFactory>().As<ISchedulerFactory>().SingleInstance();

            // Application Services
            builder.RegisterAssemblyTypes(Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, "GitSyncApp.Services.dll")))
                .AsImplementedInterfaces()
                .SingleInstance();

            // Self
            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .AsSelf()
                .InstancePerDependency();

            return app;
        }
    }
}
